package com.h3c.nem.controller;

import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.util.Result;
import com.h3c.nem.dto.TbWorkerExperienceDTO;
import com.h3c.nem.service.ITbWorkerExperienceService;
import com.h3c.nem.utils.AppBusinessException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制层
 *
 * @author chenyifan
 * @since 2022-06-06 15:46:12
 */
@Slf4j
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/tbWorkerExperience")
public class TbWorkerExperienceController {
    /**
     * 服务对象
     */
    private final ITbWorkerExperienceService tbWorkerExperienceService;

    @PostMapping("/saveWorkExperience")
    public Result saveWorkExperience(@RequestBody List<TbWorkerExperienceDTO> workerExperienceDTOS){
        try {
            tbWorkerExperienceService.saveWorkExperience(workerExperienceDTOS);
            return new Result(true, StatusCodeEnum.NORMAL);
        } catch (AppBusinessException e) {
            log.error(e.getMessage());
            //有校验异常时返回状态码401给前端弹窗提醒
            return new Result(false, 401, e.getMessage());
        } catch (Exception e) {
            log.error("", e);
            return new Result(false, 20402, e.getMessage());
        }
    }

    @GetMapping("/showWorkExperience")
    public Result showWorkExperience(){
        try {
            return new Result(true, StatusCodeEnum.NORMAL,tbWorkerExperienceService.showWorkExperience());
        } catch (Exception e) {
            log.error(e.getMessage());
            return new Result(false, 20402, e.getMessage());
        }
    }

}

